package com.yj.suncity.utis;

import java.util.Calendar;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.Context;
import android.widget.DatePicker;
import android.widget.TimePicker;

public class TimePickUtils {

	private static String date;
	private static String time;

	public static void dateSelect(Context context,
			final OnTimeDateSelectListener onTimeDateSelectListener) {
		
		DatePickerDialog datePicker;
		int year, monthOfYear, dayOfMonth;
		Calendar calendar = Calendar.getInstance();
		year = calendar.get(Calendar.YEAR);
		monthOfYear = calendar.get(Calendar.MONTH);
		dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		datePicker = new DatePickerDialog(context, new OnDateSetListener() {
			@Override
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				if (dayOfMonth < 10 && monthOfYear < 9) {
					date = year + "-0" + (monthOfYear + 1) + "-0" + dayOfMonth;

				} else if (dayOfMonth < 10 && monthOfYear > 8) {
					date = year + "-" + (monthOfYear + 1) + "-0" + dayOfMonth;

				} else if (dayOfMonth > 9 && monthOfYear > 8) {
					date = year + "-" + (monthOfYear + 1) + "-" + dayOfMonth;

				} else if (dayOfMonth > 9 && monthOfYear < 9) {
					date = year + "-0" + (monthOfYear + 1) + "-" + dayOfMonth;

				}
				view.getDrawingTime();
				onTimeDateSelectListener.onDateListener(date);
			}
		}, year, monthOfYear, dayOfMonth);

		datePicker.show();
	}

	public static void TimeSelect(Context context,
			final OnTimeDateSelectListener onTimeDateSelectListener) {
		TimePickerDialog timePicker;
		int hourOfDay, minute;

		Calendar calendar = Calendar.getInstance();
		hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
		minute = calendar.get(Calendar.MINUTE);

		timePicker = new TimePickerDialog(context, new OnTimeSetListener() {
			String hour, minute1;

			@Override
			public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
				if (hourOfDay < 10) {
					hour = "0" + hourOfDay;
				} else {
					hour = "" + hourOfDay;
				}
				if (minute < 10) {
					minute1 = "0" + minute;
				} else {
					minute1 = "" + minute;
				}
				time = hour + ":" + minute1;
				onTimeDateSelectListener.onDateListener(time);
			}
		}, hourOfDay, minute, true);
		timePicker.show();
	}

	public interface OnTimeDateSelectListener {
		void onDateListener(String time);
	}
}
